package com.globallogic.learning.kozius.entity;

import com.globallogic.learning.kozius.actor.Student;

import java.util.ArrayList;
import java.util.List;

/**
 * Class aggregates students to a course
 * <p/>
 * Created by sergii.koziumynskyi on 2/4/14.
 */
public final class Course {
    public Course(String name, String profession) {
        this.name = name;
        this.profession = profession;
    }

    public Course() {
    }

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public String getProfession() {
        return profession;
    }

    public List<Student> getEnrolledStudents() {
        return enrolledStudents;
    }

    public Curriculum getCurriculum() {
        return curriculum;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setProfession(String profession) {
        this.profession = profession;
    }

    public void setEnrolledStudents(List<Student> enrolledStudents) {
        this.enrolledStudents = enrolledStudents;
    }

    public void setCurriculum(Curriculum curriculum) {
        this.curriculum = curriculum;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Course course = (Course) o;

        if (id != course.id) return false;
        if (curriculum != null ? !curriculum.equals(course.curriculum) : course.curriculum != null) return false;
        if (enrolledStudents != null ? !enrolledStudents.equals(course.enrolledStudents) : course.enrolledStudents != null)
            return false;
        if (name != null ? !name.equals(course.name) : course.name != null) return false;
        if (profession != null ? !profession.equals(course.profession) : course.profession != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + (profession != null ? profession.hashCode() : 0);
        result = 31 * result + (enrolledStudents != null ? enrolledStudents.hashCode() : 0);
        result = 31 * result + (curriculum != null ? curriculum.hashCode() : 0);
        result = 31 * result + id;
        return result;
    }

    @Override
    public String toString() {
        return "Course{" +
                "name='" + name + '\'' +
                ", profession='" + profession + '\'' +
                ", enrolledStudents=" + enrolledStudents +
                ", curriculum=" + curriculum +
                ", id=" + id +
                '}';
    }

    private String name = "";
    private String profession = "";
    private List<Student> enrolledStudents = new ArrayList<Student>();
    private Curriculum curriculum;
    private int id;
    private static int nextId = 800000000; // 8 prefix will show that it is a course

    {
        id = nextId;
        nextId++;
    }
}
